package com.xteam.youin_supplier.fragment;


import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

import com.umeng.update.UmengUpdateAgent;
import com.umeng.update.UmengUpdateListener;
import com.umeng.update.UpdateResponse;
import com.umeng.update.UpdateStatus;
import com.xteam.youin_supplier.MainActivity;
import com.xteam.youin_supplier.R;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EFragment;
import org.androidannotations.annotations.ViewById;

/**
 * 版本更新
 */
@EFragment(R.layout.fragment_version_update)
public class VersionUpdateFragment extends BaseFragment {

    @ViewById(R.id.back_btn)
    ImageButton backBtn;

    @ViewById(R.id.toptitle_title)
    TextView topTitle;

    @AfterViews
    @Override
    void initView() {
        backBtn.setVisibility(View.VISIBLE);
        topTitle.setText(getResources().getString(R.string.version_title));

        UmengUpdateAgent.forceUpdate(MainActivity.getInstance());
        UmengUpdateAgent.setUpdateListener(new UmengUpdateListener() {
            @Override
            public void onUpdateReturned(int updateStatus, UpdateResponse updateInfo) {
                switch (updateStatus) {
                    case UpdateStatus.Yes: // has update
                        UmengUpdateAgent.showUpdateDialog(MainActivity.getInstance(), updateInfo);
                        break;
                    case UpdateStatus.No: // has no update
                        Toast.makeText(MainActivity.getInstance(), "没有更新", Toast.LENGTH_SHORT).show();
                        break;
                    case UpdateStatus.NoneWifi: // none wifi
                        Toast.makeText(MainActivity.getInstance(), "没有wifi连接， 只在wifi下更新", Toast.LENGTH_SHORT).show();
                        break;
                    case UpdateStatus.Timeout: // time out
                        Toast.makeText(MainActivity.getInstance(), "超时", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });
    }

    @Click(R.id.back_btn)
    @Override
    void Click(View view) {
    switch (view.getId()) {
     case R.id.back_btn:
         MainActivity.getInstance().getSupportFragmentManager().popBackStack();
         break;
        }
    }
}
